<?php

/**
 * Controller_pms
 * 权限管理
 */


class Controller_pms extends MyApp {

	public function __construct()
	{

		parent::__construct();

		$this->model->menu = YOU::loadModel('menu');
	}

	/** 首页 **/
	public function actionIndex ()
	{


	}


	/** 用户列表 **/
	public function actionList()
	{

		
		$user_type = $this->get->user_type;
		// 教师 编号 姓名  查询   学生班级列表  学号 姓名查询 
		
		
		
		if ($user_type == "staff"){
			
			// 分页显示
			//$user_lists = $this-
			
			
			
			
			
		}
		
		


		$this->tpl->assign("pms/pms.list.tpl.php");
	}

	/** 用户权限 **/
	public function actionInfo ()
	{
		$group_id  = (int)$this->get->group_id;

		$user_id   = (int)$this->get->user_id;
		$user_id = 1;
		$user_data = $this->db->fetchRow("SELECT user_pms FROM `tbl_user` WHERE user_id='{$user_id}'");
		if (empty($user_data)){
			Helper_Client::alert("用户不存在");
		}

		if ($_POST){
			$pid = $this->post->pid;
			$user_pms = serialize($pid);

			$info = array(
			"user_pms" => $user_pms,
			);
			$this->db->do_update("tbl_user", $info, "user_id='{$user_id}'");

			// 跳转
			Helper_Client::location("操作成功", "index.php?a=pms.list");
		}


		// 选中
		if (!empty($group_id)){
			$group_data = $this->db->fetchRow("SELECT * FROM `tbl_group` WHERE group_id='{$group_id}'");
			$group_pms  = unserialize($group_data['group_pms']);
			foreach ((array)$group_pms as $key => $value){
				$pms[$value]++;
			}
		}else{
			$user_pms = unserialize($user_data['user_pms']);
			foreach ((array)$user_pms as $key => $value){
				$pms[$value]++;
			}
		}

		// 读出所有的菜单方法
		$pms_lists = $this->model->menu->getAll();
		foreach ($pms_lists as $key => $value){
			if ($pms[$value['menu_id']] && !empty($pms[$value['menu_id']])){
				$pms_lists[$key]['is_check'] = 1;
			}
		}


		$group_lists = $this->db->fetchAll("SELECT group_id,group_name FROM `tbl_group`");

		$this->tpl->assign("group_id", $group_id);
		$this->tpl->assign("group_lists", $group_lists);
		$this->tpl->assign("pms_lists", $pms_lists);
		$this->tpl->display("pms/pms.info.tpl.php");
	}


	/** 停用 **/
	public function actionDeny()
	{




	}


	/** 启用 **/
	public function actionStart()
	{




	}



}



?>